package com.weixing.mall.provider.controller.admin;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.query.GoodsQuery;
import com.weixing.mall.provider.service.RecycleBinService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wx
 * @Date 2019/8/8 16:23
 * @Version 1.0
 */
@RestController
@RequestMapping("recycleBin")
@Api(value = "商品回收站API",tags = "商品回收站")
public class RecycleBinController extends BaseController {

    @Autowired
    private RecycleBinService recycleBinService;

    @ApiOperation("查询商品回收站")
    @GetMapping("")
    public Result list(GoodsQuery goodsQuery){
        return ResultUtil.success(recycleBinService.selectList(initMpPage(),goodsQuery));
    }


    @ApiOperation(value = "彻底删除")
    @PostMapping("delAll/{ids}")
    public Result DeleteCompletely(@PathVariable int [] ids){
        Integer order=recycleBinService.findOrder(ids);
        Integer product=recycleBinService.findProduct(ids);
        if(order>0||product>0){
            return ResultUtil.error("订单或者仓库中存在该商品无法删除");
        }
        recycleBinService.deleteCompletely(ids);
        return ResultUtil.success();
    }

    @ApiOperation(value = "恢复")
    @PostMapping("recovery/{ids}")
    public Result Recovery(@PathVariable int [] ids) {
        recycleBinService.Recovery(ids);
        return ResultUtil.success();
    }
}
